package com.crm.web.controller.clue;

import com.crm.common.core.controller.BaseController;
import com.crm.common.core.domain.AjaxResult;
import com.crm.common.core.page.TableDataInfo;
import com.crm.domain.vo.CourseVo;
import com.crm.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/clues/course")
public class CourseController extends BaseController {
    @Autowired
    private CourseService courseService;

    /**
     * 课程分页展示
     *
     * @param courseVo
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CourseVo courseVo) {
        startPage();
        List<CourseVo> list = courseService.selectCourseList(courseVo);
        return getDataTable(list);
    }

    /**
     * 课程下拉列表
     */
    @GetMapping("/listselect")
    public AjaxResult list(String subject) {
        CourseVo query = new CourseVo();
        if (subject != null) {
            query.setSubject(subject);
        }
        return AjaxResult.success(courseService.selectCourseList(query));
    }

    /**
     * 根据课程id查询课程信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        log.info("课程id：" + id);
        return AjaxResult.success(courseService.getCourseById(id));
    }

    /**
     * 课程添加
     *
     * @param courseVo
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody CourseVo courseVo) {
        return toAjax(courseService.insertCourse(courseVo));
    }

    /**
     * 课程修改
     *
     * @param courseVo
     * @return
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CourseVo courseVo) {
        return toAjax(courseService.updateCourse(courseVo));
    }
    /**
     * 课程删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseService.deleteCourseByIds(ids));
    }
}